Dart クラス装飾子の特徴早見表

attribute インスタンス化できる? extends できる? implements できる? 備考
abstract
base
interface
abstract interface 純粋な Interfacce として使える
final

mixin class

mixin のように扱えつつもインスタンス化できる。
mixin 同様に extends できずコンストラクタも宣言できない。

mixin class Horse {}
mixin Bird {}

class Pegasus with Bird, Horse {} // `with` で Horse を mixin
final horse = Horse(); // インスタンス化できる

sealed class

Enum のように扱える。
外部ではすべてのサブタイプ化が禁止され、暗黙的に abstruct class とされる。

// Library 1

sealed class Shape {
  abstract int corner;
}

// Shape shape = Shape(); ❌

class Recctangle extends Shape {
  @override
  int corner = 4;
}

class Triangle extends Shape { ... }
class Circle extends Shape { ... }

// Library 2

// サブクラス化できない
// class Rectangle extends Shape { ... }

final Shape shape = getShape();

switch (shape) {
  case Rectangle():
    ...
  case Triangle():
    ...
  case Circle():
    ...
}

Dart